﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities.Presentation.PropertyEditing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using Microsoft.Win32;
using System.Activities;
using WFDataBaseProject;
using System.Windows.Markup;
using System.IO;
using WFDataBaseProject.Controls;

namespace WFDataBaseProject.Helpers
{
    public class FilePickerEditor : DialogPropertyValueEditor
    {
        public FilePickerEditor()
        {
            this.InlineEditorTemplate = new DataTemplate();
            FrameworkElementFactory stack = new FrameworkElementFactory(typeof(StackPanel));
            stack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
            FrameworkElementFactory label = new FrameworkElementFactory(typeof(Label));
            Binding labelBinding = new Binding("StringValue");
            label.SetValue(Label.ContentProperty, labelBinding);
            label.SetValue(Label.MinWidthProperty, 90.0);
            stack.AppendChild(label);
            FrameworkElementFactory editModeSwitch = new FrameworkElementFactory(typeof(EditModeSwitchButton));
            editModeSwitch.SetValue(EditModeSwitchButton.TargetEditModeProperty, PropertyContainerEditMode.Dialog);
            stack.AppendChild(editModeSwitch);
            this.InlineEditorTemplate.VisualTree = stack;
        }
        public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
        {
            base.ShowDialog(propertyValue,commandSource);
            Microsoft.Win32.OpenFileDialog openfiledialog = new Microsoft.Win32.OpenFileDialog();
            //openfiledialog.Filter = "(*.txt)|*.txt(sql.*)|*.sql";
            if (openfiledialog.ShowDialog() == true)
            {
                propertyValue.StringValue = openfiledialog.FileName;
            }
        }
    }
}
